import 'package:dio/dio.dart';

import 'http_code.dart';

class HttpResponse<T> {
  T? data;
  String? msg;
  int? code;
  DioExceptionType? type;
  // int timeStamp;

  HttpResponse({
    this.data,
    this.code,
    this.msg,
    this.type,
    // this.timeStamp = 0,
  });

  factory HttpResponse.fromJson(Map? json) => HttpResponse(
        data: json?["data"],
        code: json?["code"],
        // timeStamp: json?["timeStamp"] ?? 0,
        msg: json?["msg"] ?? json?["message"],
      );

  bool get isSuccess {
    return HttpCode.code0 == code && data != null;
  }

  String get codeAndMsg {
    return "${code ?? ""} $msg";
  }
}
